package com.xjm.controller;

import com.xjm.entity.HeadLine;
import com.xjm.service.HeadLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * com.xjm.controller
 *
 * @author jaymin
 * @since 2021/5/26
 */
@RequestMapping("/headline")
@Controller
public class HeadlineController {

	@Autowired
	private HeadLineService headLineService;

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public ModelAndView addHeadline(@RequestParam("lineName") String lineName,
									@RequestParam("lineLink") String lineLink,
									@RequestParam("lineImg") String lineImg,
									@RequestParam("priority") Integer priority) {
		HeadLine headLine = HeadLine.builder().lineName(lineName)
				.lineLink(lineLink)
				.lineImg(lineImg)
				.priority(priority)
				.build();
		ModelAndView modelAndView = new ModelAndView();
		System.out.println("我被调用了");
		modelAndView.setViewName("hello");
		modelAndView.addObject("result", headLine);
		return modelAndView;
	}

	@GetMapping(value = "/open")
	public String openPage() {
		return "hello";
	}

	@GetMapping(value = "/hello")
	public String hello() {
		return "hello";
	}
}
